package com.es.service.impl;

import com.es.dao.CCBAccountDao;
import com.es.entity.CCBAccount;
import com.es.service.CCBAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;

@Service
public class CCBAccountServiceImpl implements CCBAccountService {

    @Autowired
    private CCBAccountDao dao;

    @Override
    @Transactional(noRollbackFor = ArithmeticException.class)
    public int createAccount(CCBAccount ccbAccount) {
        return dao.createAccount(ccbAccount);
    }

    @Override
    public int withdraw(String cardNo, BigDecimal mount) {
        return 0;
    }

    @Override
    @Transactional
    public int deposit(String cardNo, BigDecimal mount) {
        return dao.deposit(cardNo, mount);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public int trans(String from, String to, BigDecimal mount) {
        dao.withdraw(from, mount);
        dao.deposit(to, mount);
        return 0;
    }

    @Override
    @Transactional(isolation = Isolation.READ_UNCOMMITTED)
    public CCBAccount get(Integer id) {
        return dao.get(id);
    }
    //
}
